
#include <QtGui>
#include "ticker.h"
Ticker::Ticker(QWidget *parent) : QWidget(parent)
{
    smewenie = 0;
    myTimerId = 0;
}
void Ticker::setText(const QString &newText)
{
    myText = newText;
    update();
    updateGeometry();
}
QSize Ticker::sizeHint() const
{
    return fontMetrics().size(0, text());
}
void Ticker::paintEvent(QPaintEvent * )
{
    QPainter painter(this);
    int textWidth = fontMetrics().width(text());
    if (textWidth < 1)
    return;
    int x= -smewenie;
    while (x < width()) {
        painter.drawText(x, 0, textWidth, height(), Qt::AlignLeft | Qt::AlignVCenter, text());
        x+=textWidth;
    }
}
//void Ticker::showEvent(QShowEvent * /* event */)
//{
 //   myTimerId = startTimer(51);
//}

void Ticker::change(int k)
{
    myTimerId = startTimer(100-k);
}

void Ticker::timerEvent(QTimerEvent *event)
{
    if (event->timerId() == myTimerId) {
    ++smewenie;
    if (smewenie >= fontMetrics().width(text()))
    smewenie = 0;
    scroll(-1, 0);
    } else {
    QWidget::timerEvent(event);
    }
}
//void Ticker::hideEvent(QHideEvent * /* event */)
//{
//    killTimer(myTimerId);
//    myTimerId = 0;
//}

